<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Logic;


class ClcwMessageReceiveLogic extends BaseLogic
{
    protected $autoCheckFields = false;

    protected $clcwMessageReceiveModel;

    public function _initialize()
    {
        $this->clcwMessageReceiveModel = D('ClcwMessageReceive', 'Model');
    }

    /**
     * 获取所有接收者的用户ID
     *
     * @param int $msgId
     */
    public function getUserIdsByMsgId($msgId = 0)
    {
        if (empty($msgId)) {
            return false;
        }
        $condition = [];
        $condition['msg_id'] = $msgId;
        $list = $this->clcwMessageReceiveModel->where($condition)->select();
        $userIds = [];
        if (!empty($list)) {
            foreach ($list as $k => $v) {
                $userIds[$k] = $v['user_id'];
            }
        }
        if (!empty($userIds)) {
            $userIdStr = implode(',', $userIds);
        } else {
            $userIdStr = '';
        }
        return $userIdStr;
    }

    /**
     * 添加接收人数据
     *
     * @param array $data
     */
    public function addMessageReceive($data = [])
    {
        if (empty($data)) {
            return false;
        }
        return $this->clcwMessageReceiveModel->add($data);
    }

}